﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using DataStructuresCSharp.KeyValueCollection;

namespace DataStructuresCSharp.Node
{
    public class AvlTreeNode<TKey, TValue> : BaseBinaryTreeNode<KeyValuePair<TKey, TValue>, AvlTreeNode<TKey, TValue>>
    {
        /// <summary>
        /// Notice that the node class stores its parent, this isn’t necessary, but if you don’t you’ll need to keep track of the parents as the tree is traversed which would make the algorithm slower, but lighter on memory.
        /// </summary>
        public AvlTreeNode<TKey, TValue> Parent
        {
            get { return Children[2]; }
            set { Children[2] = value; }
        }

        public int BalanceFactor { get; set; }

        public AvlTreeNode(TKey key, TValue value, int balanceFactor = 0, AvlTreeNode<TKey, TValue> left = null, AvlTreeNode<TKey, TValue> right = null, AvlTreeNode<TKey, TValue> parent = null)
            : this(new KeyValuePair<TKey, TValue>(key, value), balanceFactor, left, right, parent) { }

        public AvlTreeNode(KeyValuePair<TKey, TValue> item, int balanceFactor = 0, AvlTreeNode<TKey, TValue> left = null, AvlTreeNode<TKey, TValue> right = null, AvlTreeNode<TKey, TValue> parent = null)
            : base(3, item, left, right)
        {
            BalanceFactor = balanceFactor;
            Parent = parent;
        }
    }

}
